package com.example.rabbitdemo.exchanger.headers;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

// 2. 生产者：发送带Headers的消息
@Service
public class HeadersProducer {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void sendJsonMessage() {
        MessageProperties props = new MessageProperties();
        props.setHeader("format", "json");
        props.setHeader("type", "report");
        Message message = new Message("JSON消息体".getBytes(), props);
        // 路由键在Headers Exchange中通常被忽略
        rabbitTemplate.send("exchange.headers", "", message);
    }
}